package cc.io24.knewcafe.boss.controller;

import cc.io24.knewcafe.boss.domain.SysUser;
import cc.io24.knewcafe.boss.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/SysUser")
public class SysUserController extends BaseController<SysUser> {

    @Autowired
    public void setSysUserService(SysUserService sysUserService) {
        super.setService(sysUserService);
    }

    @Override
    public List<SysUser> getList(@ModelAttribute SysUser sysUser, @PageableDefault(value = 10, sort = {"nickname"}, direction = Sort.Direction.DESC) Pageable pageable, HttpServletResponse response) {
        return super.getList(sysUser, pageable, response);
    }

//    @GetMapping(value = "",produces="application/json")
//    public List<SysUser> getList(@ModelAttribute SysUser sysUser,
//                                   @PageableDefault(value = 10, sort = { "createDate" }, direction = Sort.Direction.DESC)Pageable pageable,
//                                   HttpServletResponse response){
//        Page<SysUser> page =  super.getService().getList(sysUser,pageable);
//        response.addHeader("X-Total-Count",page.getTotalElements()+"");
//        response.addHeader("Access-Control-Expose-Headers","X-Total-Count");
//        return page.getContent();
//    }

//    @GetMapping(value = "/{id}",produces="application/json")
//    public SysUser getOne(@PathVariable("id")String id,
//                                   HttpServletResponse response){
//        SysUser sysUser =  sysUserService.getOne(id);
//        // response.addHeader("X-Total-Count",page.getTotalElements()+"");
//        // response.addHeader("Access-Control-Expose-Headers","X-Total-Count");
//        return sysUser;
//    }
//
//
//    @PostMapping(value = "",produces="application/json")
//    public SysUser create(@RequestBody SysUser sysUser,
//                          HttpServletResponse response){
//        System.out.println(sysUser.getNickname());
//        return sysUserService.register(sysUser);
//    }
//
//    @PutMapping(value = "/{id}",produces="application/json")
//    public SysUser update(@PathVariable("id")String id,
//                          @RequestBody SysUser sysUser,
//                          HttpServletResponse response){
//        sysUser.setId(id);
//        return sysUserService.update(sysUser);
//    }
//
//    @DeleteMapping(value = "/{id}",produces="application/json")
//    public void delete(@PathVariable("id")String id,
//                          HttpServletResponse response){
//        sysUserService.deleteById(id);
//    }

}
